//
//  AuctionCollectionHeaderCouponsView.m
//  MyNewProject
//
//  Created by 王春辉 on 2019/12/23.
//  Copyright © 2019年 sun. All rights reserved.
//

#import "AuctionCollectionHeaderCouponsView.h"
#import "UIView+GradientLayer.h"

@interface AuctionCollectionHeaderCouponsView()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *moneyLabel;

@property (nonatomic, strong) UILabel *titleLabel1;
@property (nonatomic, strong) UILabel *titleLabel2;
@property (nonatomic, strong) UILabel *realPriceLabel1;
@property (nonatomic, strong) UILabel *realPriceLabel2;
@property (nonatomic, strong) UILabel *priceLabel1;
@property (nonatomic, strong) UILabel *priceLabel2;
@end
@implementation AuctionCollectionHeaderCouponsView
@synthesize imageView1 = _imageView1;
@synthesize imageView2 = _imageView2;

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.layer.masksToBounds = true;
        self.layer.cornerRadius = 4.0;
        [self initContentViews];
    }
    return self;
}

/**
 初始化contentViews
 */
- (void)initContentViews {
    UIImageView *imageView = [[UIImageView alloc] initWithImage:SKIMAGE_NAMED(@"auction_header_new_coupon_bg_img")];
    [self addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];
    
    UIView *whiteView = [[UIView alloc] init];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.layer.masksToBounds = true;
    whiteView.layer.cornerRadius = 4.0;
    [self addSubview:whiteView];
    
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(10);
        make.right.mas_offset(-10);
        make.bottom.mas_offset(-10);
        make.width.mas_equalTo(whiteView.mas_height).multipliedBy(230.0 / 167);
    }];
    
    [whiteView addSubview:self.imageView1];
    [whiteView addSubview:self.imageView2];
    [whiteView addSubview:self.titleLabel1];
    [whiteView addSubview:self.titleLabel2];
    [whiteView addSubview:self.priceLabel1];
    [whiteView addSubview:self.priceLabel2];
    [whiteView addSubview:self.realPriceLabel1];
    [whiteView addSubview:self.realPriceLabel2];
    
    UILabel *moneyTip1 = [[UILabel alloc] init];
    moneyTip1.text = @"¥";
    moneyTip1.font = SKFONT_BOLD_SIZE(10);
    moneyTip1.textColor = SKColorWithHex(0xFF3030);

    UILabel *moneyTip2 = [[UILabel alloc] init];
    moneyTip2.text = @"¥";
    moneyTip2.font = SKFONT_BOLD_SIZE(10);
    moneyTip2.textColor = SKColorWithHex(0xFF3030);
    
    [whiteView addSubview:moneyTip1];
    [whiteView addSubview:moneyTip2];
    
    [self.imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_offset(10);
        make.right.mas_equalTo(self.imageView2.mas_left).mas_offset(-10);
        make.height.mas_equalTo(self.imageView1.mas_width);
    }];
    
    [self.imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.imageView1);
        make.right.mas_offset(-10);
        make.size.mas_equalTo(self.imageView1);
    }];
    
    [moneyTip1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imageView1).mas_offset(3.0);
        make.bottom.mas_offset(-10);
    }];
    
    [self.realPriceLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(moneyTip1.mas_right).mas_offset(2);
        make.bottom.mas_equalTo(moneyTip1);
        make.height.mas_equalTo(15);
    }];
    
    [self.priceLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.realPriceLabel1.mas_right).mas_offset(2);
        make.bottom.mas_equalTo(self.realPriceLabel1);
    }];
    
    [self.titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imageView1);
        make.top.mas_equalTo(self.imageView1.mas_bottom);
        make.bottom.mas_equalTo(self.realPriceLabel1.mas_top);
        make.right.mas_lessThanOrEqualTo(self.imageView1);
    }];
    
    [moneyTip2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imageView2).mas_offset(3.0);
        make.bottom.mas_equalTo(moneyTip1);
    }];
    
    [self.realPriceLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(moneyTip2.mas_right).mas_offset(2);
        make.bottom.mas_equalTo(moneyTip2);
        make.height.mas_equalTo(self.realPriceLabel1);
    }];
    
    [self.priceLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.realPriceLabel2.mas_right).mas_offset(2);
        make.bottom.mas_equalTo(self.priceLabel1);
    }];
    
    [self.titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imageView2);
        make.top.mas_equalTo(self.imageView2.mas_bottom);
        make.bottom.mas_equalTo(self.titleLabel1);
        make.right.mas_lessThanOrEqualTo(self.imageView2);
    }];
    
    UIButton *useButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [useButton setTitle:@"去使用" forState:UIControlStateNormal];
    [useButton setTitleColor:SKColorWithHex(0xA44E00) forState:UIControlStateNormal];
    useButton.backgroundColor = SKColorWithHex(0xF6CAA3);
    useButton.titleLabel.font = SKFONT_BOLD_SIZE(17);
    useButton.layer.masksToBounds = true;
    [useButton addTarget:self action:@selector(useButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:useButton];
    useButton.tag = 520;
    
    UILabel *tipLabel = [[UILabel alloc] init];
//    tipLabel.font = SKFONT_BOLD_SIZE(18);
    tipLabel.textColor = SKColorWithHex(0xF5EBD6);
    [self addSubview:tipLabel];
    NSShadow *shadow=[[NSShadow alloc]init];
    shadow.shadowBlurRadius = 1.0;
    shadow.shadowOffset = CGSizeMake(0, 0);
    shadow.shadowColor = SKColorWithHex(0xFF4B2F);
    NSAttributedString *attributeS = [[NSAttributedString alloc] initWithString:@"¥" attributes:@{NSShadowAttributeName:shadow, NSFontAttributeName:SKFONT_BOLD_SIZE(18)}];
    tipLabel.attributedText = attributeS;
    
    UILabel *couponsLabel = [[UILabel alloc] init];
    couponsLabel.textColor = [UIColor whiteColor];
    couponsLabel.text = @"优惠券";
    couponsLabel.textAlignment = NSTextAlignmentCenter;
    couponsLabel.font = SKFONT_BOLD_SIZE(18);
    [self addSubview:couponsLabel];
    
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(4);
        make.centerY.mas_equalTo(whiteView.centerY).mas_offset(-12);
    }];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tipLabel.mas_right).mas_offset(2);
        make.right.mas_lessThanOrEqualTo(whiteView.mas_left).mas_offset(-4);
        make.bottom.mas_equalTo(tipLabel).mas_offset(4);
    }];
    
    [couponsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.right.mas_equalTo(whiteView.mas_left).mas_offset(-10);
        make.centerY.mas_equalTo(whiteView.centerY).mas_offset(12);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(couponsLabel);
        make.bottom.mas_equalTo(tipLabel.mas_top).mas_offset(-20);
    }];
    
    [useButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(couponsLabel);
        make.top.mas_equalTo(couponsLabel.mas_bottom).mas_offset(10);
        make.left.mas_offset(8.5);
        make.height.mas_equalTo(useButton.mas_width).multipliedBy(34.0/84);
    }];
    
//    useButton.startColor = SKColorWithHex(0xF5EBD6);
//    useButton.endColor = SKColorWithHex(0xF5EBD6);
//    [useButton showGradientLayer];
    
//    self.moneyLabel.startColor = SKColorWithHex(0xFFAE75);
//    self.moneyLabel.endColor = SKColorWithHex(0xA44E00);
//    [self.moneyLabel showGradientLabelLayer];
    self.imageView1.userInteractionEnabled = true;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap1:)];
    [self.imageView1 addGestureRecognizer:tap1];
    self.imageView2.userInteractionEnabled = true;
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap2:)];
    [self.imageView2 addGestureRecognizer:tap2];
    
}
- (void)layoutSubviews {
    [super layoutSubviews];
    UIButton *btn = [self viewWithTag:520];
    btn.layer.cornerRadius = btn.height * 0.5;
//    btn.gradientLayer.frame = btn.bounds;
//    self.moneyLabel.gradientLayer.frame = self.moneyLabel.bounds;
//    self.moneyLabel.gradientLabel.frame = self.moneyLabel.bounds;
}

#pragma mark -- mark 懒加载
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = SKFONT_BOLD_SIZE(18);
        _titleLabel.text = @"新人专享";
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}
- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        self.moneyLabel = [[UILabel alloc] init];
        _moneyLabel.textColor = SKColorWithHex(0xF5EBD6);
        _moneyLabel.font = SKFONT_BOLD_SIZE(34);
        [self addSubview:_moneyLabel];
    }
    return _moneyLabel;
}

- (UIImageView *)imageView1 {
    if (!_imageView1) {
        _imageView1 = [[UIImageView alloc] init];
        _imageView1.layer.masksToBounds = true;
        _imageView1.layer.cornerRadius = 4.0;
        _imageView1.backgroundColor = [UIColor lightGrayColor];
    }
    return _imageView1;
}
- (UIImageView *)imageView2 {
    if (!_imageView2) {
        _imageView2 = [[UIImageView alloc] init];
        _imageView2.layer.masksToBounds = true;
        _imageView2.layer.cornerRadius = 4.0;
        _imageView2.backgroundColor = [UIColor lightGrayColor];
    }
    return _imageView2;
}
- (UILabel *)titleLabel1 {
    if (!_titleLabel1) {
        self.titleLabel1 = [[UILabel alloc] init];
        _titleLabel1.textColor = SKColorWithHex(0x333333);
        _titleLabel1.font = SKFONT_BOLD_SIZE(13);
    }
    return _titleLabel1;
}
- (UILabel *)titleLabel2 {
    if (!_titleLabel2) {
        self.titleLabel2 = [[UILabel alloc] init];
        _titleLabel2.textColor = SKColorWithHex(0x333333);
        _titleLabel2.font = SKFONT_BOLD_SIZE(13);
    }
    return _titleLabel2;
}
- (UILabel *)realPriceLabel1 {
    if (!_realPriceLabel1) {
        self.realPriceLabel1 = [[UILabel alloc] init];
        _realPriceLabel1.textColor = SKColorWithHex(0xFF3030);
        _realPriceLabel1.font = SKFONT_BOLD_SIZE(13);
    }
    return _realPriceLabel1;
}
- (UILabel *)realPriceLabel2 {
    if (!_realPriceLabel2) {
        self.realPriceLabel2 = [[UILabel alloc] init];
        _realPriceLabel2.textColor = SKColorWithHex(0xFF3030);
        _realPriceLabel2.font = SKFONT_BOLD_SIZE(13);
    }
    return _realPriceLabel2;
}
- (UILabel *)priceLabel1 {
    if (!_priceLabel1) {
        self.priceLabel1 = [[UILabel alloc] init];
        NSString *text = @"¥ 889.8";
        NSAttributedString *attributeS = [[NSAttributedString alloc] initWithString:text attributes:@{NSForegroundColorAttributeName:SKColorWithHex(0xB1B1B1), NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSFontAttributeName:SKFONT_BOLD_SIZE(10)}];
        _priceLabel1.attributedText = attributeS;
    }
    return _priceLabel1;
}
- (UILabel *)priceLabel2 {
    if (!_priceLabel2) {
        self.priceLabel2 = [[UILabel alloc] init];
        NSString *text = @"¥ 889.8";
        NSAttributedString *attributeS = [[NSAttributedString alloc] initWithString:text attributes:@{NSForegroundColorAttributeName:SKColorWithHex(0xB1B1B1), NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSFontAttributeName:SKFONT_BOLD_SIZE(10)}];
        _priceLabel2.attributedText = attributeS;
    }
    return _priceLabel2;
}

#pragma mark -- mark 设置参数
- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}
- (void)setMoneyNum:(CGFloat)moneyNum {
    _moneyNum = moneyNum;
    NSString *str = [NSString stringWithFormat:@"%.0f", moneyNum];
    NSShadow *shadow=[[NSShadow alloc]init];
    shadow.shadowBlurRadius = 1.0;
    shadow.shadowOffset = CGSizeMake(0, 0);
    shadow.shadowColor = SKColorWithHex(0xFF4B2F);
    NSAttributedString *attributeS = [[NSAttributedString alloc] initWithString:str attributes:@{NSShadowAttributeName:shadow, NSFontAttributeName:self.moneyLabel.font}];
    self.moneyLabel.attributedText = attributeS;
}
- (void)setTitle1:(NSString *)title1 {
    _title1 = title1;
    self.titleLabel1.text = title1;
}
- (void)setTitle2:(NSString *)title2 {
    _title2 = title2;
    self.titleLabel2.text = title2;
}
- (void)setPrice1:(CGFloat)price1 {
    _price1 = price1;
    NSString *text = [NSString stringWithFormat:@"¥%.1f", price1];
    NSAttributedString *attributeS = [[NSAttributedString alloc] initWithString:text attributes:@{NSForegroundColorAttributeName:SKColorWithHex(0xB1B1B1), NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSFontAttributeName:SKFONT_BOLD_SIZE(10)}];
    self.priceLabel1.attributedText = attributeS;
}
- (void)setPrice2:(CGFloat)price2 {
    _price2 = price2;
    NSString *text = [NSString stringWithFormat:@"¥%.1f", price2];
    NSAttributedString *attributeS = [[NSAttributedString alloc] initWithString:text attributes:@{NSForegroundColorAttributeName:SKColorWithHex(0xB1B1B1), NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSFontAttributeName:SKFONT_BOLD_SIZE(10)}];
    self.priceLabel2.attributedText = attributeS;
}
- (void)setRealPrice1:(CGFloat)realPrice1 {
    _realPrice1 = realPrice1;
    self.realPriceLabel1.text = [NSString stringWithFormat:@"%0.f", realPrice1];
}
- (void)setRealPrice2:(CGFloat)realPrice2 {
    _realPrice2 = realPrice2;
    self.realPriceLabel2.text = [NSString stringWithFormat:@"%0.f", realPrice2];
}

#pragma mark -- mark EVENT

- (void)tap1:(UITapGestureRecognizer *)tap {
    if (self.couponProductButtonClickBlock) {
        self.couponProductButtonClickBlock(0);
    }
}
- (void)tap2:(UITapGestureRecognizer *)tap {
    if (self.couponProductButtonClickBlock) {
        self.couponProductButtonClickBlock(1);
    }
}
- (void)useButtonClick:(UIButton *)sender {
    if (self.couponUseButtonClickBlock) {
        self.couponUseButtonClickBlock(); }
}
@end
